﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class SysUpgrade
    {
        public static void insert(SysUpgradeEntity sysUpgrade)
        {
            DbHelper.ExecuteNonQuery("p_SysUpgrade_insert",
                sysUpgrade.AdminId,
                sysUpgrade.Title,
                sysUpgrade.Description,
                sysUpgrade.StartDt,
                sysUpgrade.EndDt
            );
        }

        public static void update(SysUpgradeEntity sysUpgrade)
        {
            DbHelper.ExecuteNonQuery("p_SysUpgrade_update",
                sysUpgrade.Suid,
                sysUpgrade.AdminId,
                sysUpgrade.Title,
                sysUpgrade.Description,
                sysUpgrade.StartDt,
                sysUpgrade.EndDt,
                sysUpgrade.IsShow
            );
        }

        public static void delete(int suid)
        {
            DbHelper.ExecuteNonQuery("p_SysUpgrade_delete", suid);
        }

        public static SysUpgradeEntity getById(int suid)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_sysUpgrade_getById", suid);
            SysUpgradeEntity sysUpgrade = new SysUpgradeEntity();
            if (dr != null)
            {
                sysUpgrade.Suid = int.Parse(dr["suid"].ToString());
                sysUpgrade.AdminId = int.Parse(dr["adminId"].ToString());
                sysUpgrade.Title = dr["title"].ToString();
                sysUpgrade.Description = dr["description"].ToString();
                sysUpgrade.StartDt = DateTime.Parse(dr["startDt"].ToString());
                sysUpgrade.EndDt = DateTime.Parse(dr["endDt"].ToString());
                sysUpgrade.InputDt = DateTime.Parse(dr["inputDt"].ToString());
                sysUpgrade.IsShow = Convert.ToBoolean(dr["isShow"]);
            }
            return sysUpgrade;
        }
        public static SysUpgradeEntity queryRangeTip()
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_sysUpgrade_Tip");

            SysUpgradeEntity sysUpgrade = null;
            if (dr != null)
            {
                sysUpgrade = new SysUpgradeEntity();

                sysUpgrade.Suid = int.Parse(dr["suid"].ToString());
                sysUpgrade.AdminId = int.Parse(dr["adminId"].ToString());
                sysUpgrade.Title = dr["title"].ToString();
                sysUpgrade.Description = dr["description"].ToString();
                sysUpgrade.StartDt = DateTime.Parse(dr["startDt"].ToString());
                sysUpgrade.EndDt = DateTime.Parse(dr["endDt"].ToString());
                sysUpgrade.InputDt = DateTime.Parse(dr["inputDt"].ToString());
                sysUpgrade.IsShow = Convert.ToBoolean(dr["isShow"]);
            }
            return sysUpgrade;
        }
    }
}